import rclpy
from rclpy.node import Node
from example_interfaces.srv import AddTwoInts
class service_client(Node):
    def __init__(self,name):
        super().__init__(name)
        self.get_logger().info('This is a client:{}'.format(name))
        self.client = self.create_client(AddTwoInts,'ints_add')
    def result_callbakc(self,result_future):
        response = result_future.result()
        self.get_logger().info(f'receive: {response.sum}')
    
    def send_request(self,a,b):
        while rclpy.ok() and self.client.wait_for_service(1)==False:
            self.get_logger().info(f'waiting for server ...')
        request = AddTwoInts.Request()
        request.a = a
        request.b = b
        self.client.call_async(request=request).add_done_callback(self.result_callbakc)

def main(args=None):
    rclpy.init(args=args)
    node = service_client('service_client')
    node.send_request(3,4)
    rclpy.spin(node)
    rclpy.shutdown()